Skip to content

feat: add assertEnv - #19

Merged
davidjalbers merged 1 commit into
mainfrom
feat/assert-env
Aug 7, 2026
Merged

feat: add assertEnv#19
davidjalbers merged 1 commit into
mainfrom
feat/assert-env

Conversation

@davidjalbers

Copy link
Copy Markdown
Contributor

Adds assertEnv to @plexus-ms/std: read the first environment variable that is set from a list of candidate names, or throw.

const secret = assertEnv('AUTH_SECRET', 'BETTER_AUTH_SECRET', { hint: 'use `pnx auth secret` to generate' });
const baseURL = assertEnv('APP_URL', 'AUTH_URL', 'BETTER_AUTH_URL', 'VERCEL_URL');

Names are tried in order. A variable that is unset or blank counts as missing and the returned value is trimmed, so AUTH_SECRET= fails loudly instead of handing back an empty secret.

Error messages name every candidate, Oxford-comma style, with the hint appended after a colon:

Missing environment variable AUTH_SECRET
Missing environment variable AUTH_SECRET or BETTER_AUTH_SECRET: use `pnx auth secret` to generate
Missing environment variable APP_URL, AUTH_URL, BETTER_AUTH_URL, or VERCEL_URL

Two overloads type the trailing options object and require at least one name, so assertEnv() and assertEnv({ hint }, 'A') are both compile errors.

Note: the package had no ambient types at all, so this adds @types/node and an explicit types: ["node"] for process.env.

🤖 Generated with Claude Code

Reads the first environment variable that is set from a list of candidate
names, or throws naming all of them plus an optional hint. Unset and
blank values are both treated as missing.

Needs @types/node (and an explicit `types` field, since the package
previously pulled in no ambient types) for `process.env`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@davidjalbers
davidjalbers merged commit 3c484bd into main Aug 7, 2026
2 checks passed
@davidjalbers
davidjalbers deleted the feat/assert-env branch August 7, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant